import React, {useRef} from 'react';
import ProTable, {ActionType} from '@ant-design/pro-table';
import type {FutuersDetailListProps} from './data.d';
import {queryType} from "./data.d";
import {queryFutuersDetailList} from './service';
import {queryUse} from "@/utils/service";
import {formatDate} from "@/utils/function";


const FutuersDetailList: React.FC<FutuersDetailListProps> = (props) => {
  /** 新建窗口的弹窗 */
  /*
actualAmount: 23.149
commission: 0.00008464
contractAmount: 0
contractCount: 0
fixedAmount: 90
group: "202104291655360979"
leverage: 2
status: "INTRADE"
stockAmount: 65.97188773
stockCount: 47.19
symbol: "XRPUSDT"
  * */
  const columns: any[] = [
    // {
    //   title: "订单ID",
    //   dataIndex: 'orderId',
    //   search: false,
    //   key: 'orderId',
    //   fixed: "left",
    //   width: 100,
    //   // filters: true,
    //   // onFilter: true,
    //   tip: '订单ID是唯一的 key',
    // },
    {
      title: "交易对",
      search: false,
      dataIndex: 'symbol',
      key: 'symbol',
      fixed: "left",
      width: 90,
    },
    // {
    //   title: "交易组号",
    //   search: false,
    //   dataIndex: 'group',
    //   key: 'group',
    //   fixed: "left",
    //   width: 90,
    // },
    {
      title: "交易时间",
      search: false,
      width: 120,
      dataIndex: 'createTime',
      key: 'createTime',
      renderText: (val: string) => formatDate(val, false)
    },
    {
      title: "现货交易数量",
      search: false,
      width: 80,
      dataIndex: 'stockCount',
      key: 'stockCount',
    },
    {
      title: "现货交易市值",
      search: false,
      width: 80,
      dataIndex: 'stockAmount',
      key: 'stockAmount',
    },
    {
      title: "合约数量",
      search: false,
      width: 80,
      dataIndex: 'contractCount',
      key: 'contractCount',
    },
    {
      title: "合约金额",
      search: false,
      width: 80,
      dataIndex: 'contractAmount',
      key: 'contractAmount',
    },
    {
      title: "合约杠杆",
      search: false,
      width: 100,
      dataIndex: 'leverage',
      key: 'leverage',
    },
    {
      title: "现货交易手续费",
      search: false,
      width: 80,
      key: 'commission',
      dataIndex: 'commission',
    },
   {
      title: "套利利润",
      search: false,
      width: 80,
      key: 'arbitrageProfit',
      dataIndex: 'arbitrageProfit',
    },
    {
      title: "订单类型",
      search: false,
      width: 80,
      dataIndex: 'orderMethod',
      key: 'orderMethod',
    },
  ];
  const actionRef = useRef<ActionType>();

  return (
      <ProTable<any>
        headerTitle={props.group+" 期现套利详情列表"}
        bordered
        actionRef={actionRef}
        search={false}
        scroll={{x: 1200, y: 666}}
        request={async (params = {}, sort, filter) => {
          // console.log(sort, filter);
          let payload: queryType = {
            // "adminId": 0,
            // "endTime": 0,
            // "orderId": "",
            // "startTime": 0
            group:props.group,
            page: params.current,
            pageSize: params.pageSize,
          }
          /*{
	"adminId": 0,
	"endTime": 0,
	"group": "",
	"orderId": "",
	"page": 0,
	"pageSize": 0,
	"startTime": 0
}*/
          const msg = await queryFutuersDetailList(
            payload
          );
          let data = queryUse(msg)
          if (data) {
            return {
              data: data.list,
              // success 请返回 true，
              // 不然 table 会停止解析数据，即使有数据
              success: true,
              // 不传会使用 data 的长度，如果是分页一定要传
              total: data.total,
            };
          } else {
            return {
              data: [],
              success: false,
            };
          }
        }}
        columns={columns}
        pagination={{defaultPageSize:50}}
        {...{cardProps:{bodyStyle:{paddingBottom:"20px"}}}}
      />
  );
};

export default FutuersDetailList;
